/*
 * 作者:熊猫
 * 日期:2017 - 3 - 19 9 - 8 - 33
 *
 */

package net.lainiao.morethread.Chapter7.demo7;

/**
 * Created by Administrator on 2017/3/19.
 */
public class Task extends MyWorkerTask {
    private int[] array;
    private int start,end;
    public Task(String name,int[] array,int start,int end) {
        super(name);
        this.array=array;
        this.start=start;
        this.end=end;
    }

    @Override
    protected void compute() {
        if(end-start>100){
            int middlf=start+(end-start)/2;
            Task task1=new Task(this.getName()+"A",array,start,middlf);
            Task task2=new Task(this.getName()+"B",array,middlf,end);
            invokeAll(task1,task2);
        }
        else{
            for (int i = start; i <end ; i++) {
                array[i]++;
            }
        }
        try {
            Thread.sleep(50);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("Task "+this.getName()+" is Over");
    }
}
